package org.fu.crowd.controller;

import org.fu.crowd.api.MySQLRemoteService;
import org.fu.crowd.constant.CrowdConstant;
import org.fu.crowd.utils.Common;
import org.fu.crowd.vo.PortalTypeVO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class SingleWebController {

    @Resource
    private MySQLRemoteService mySQLRemoteService;

    @RequestMapping("/admin-login")
    public String admin_login(){
        return "admin-login";
    }


    @RequestMapping("/")
    public String index(Model model){
        //调用远程数据库获取首页数据
        Common<List<PortalTypeVO>> portalTypeProjectDataRemote = mySQLRemoteService.getPortalTypeProjectDataRemote();
        //判断成功还是失败
        String result = portalTypeProjectDataRemote.getResult();
        if (Common.SUCCESS.equals(result)){
            //存入request域
            List<PortalTypeVO> data = portalTypeProjectDataRemote.getData();
            model.addAttribute(CrowdConstant.ATTR_NAME_PORTAL_DATA,data);
        }
        return "index";
    }

    @RequestMapping("/redirect")
    public String redirect(){
        return "main";
    }


    @RequestMapping("/main/user/addUser")
    public String addUser(){
        return "addUser";
    }


    @RequestMapping("/main/role")
    public String role(){
        return "role";
    }


    @RequestMapping("/menu")
    public String menu(){
        return "menu-page";
    }


    @RequestMapping("/system-error")
    public String system_error(){
        return "system-error";
    }



    @RequestMapping("/register")
    public String register(){
        return "register";
    }


    @RequestMapping("/member/login")
    public String member_login(){
        return "member-login";
    }



    @RequestMapping("/member")
    public String member(){
        return "member";
    }



}
